#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int arr[N];
int q[N];
int n, m;
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int hh = 0, tt = -1;
	for (int i = 0; i < n; i++) {
		if (hh <= tt && i - q[hh] + 1 > m) {
			hh++;
		}
		while (hh <= tt && arr[q[tt]] <= arr[i]) {
			tt--;
		}
		q[++tt] = i;
		if (i + 1 >= m) {
			cout << arr[q[hh]] << " ";
		}
	}
	return 0;
}